package com.etime.shuhuiyuan.controllers.saler;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.common.BaseMessage;
import com.etime.shuhuiyuan.common.ListMessage;
import com.etime.shuhuiyuan.common.PageMessage;
import com.etime.shuhuiyuan.common.PojoMessage;
import com.etime.shuhuiyuan.dto.SalerDto;
import com.etime.shuhuiyuan.pojo.Saler;
import com.etime.shuhuiyuan.pojo.User;
import com.etime.shuhuiyuan.services.saler.interfaces.SalerService2;
import com.etime.shuhuiyuan.services.user.interfaces.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * department示例的controller控制层
 */
@Api(tags = "saler案例接口2")
@RestController
@RequestMapping("/saler2")
public class SalerController2 {

    @Autowired
    private SalerService2 salerService2;
    @Autowired
    private UserService userService;


    @ApiOperation("添加saler案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="salerid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="salerdeptid",value="传递字符串"),
            @ApiImplicitParam(name="salercode",value = "传递销售人员推荐码"),
            @ApiImplicitParam(name="salerbankname",value="传递开户银行"),
            @ApiImplicitParam(name="salerbanknum",value = "传递银行卡号"),
            @ApiImplicitParam(name="salerauditstate",value = "传递数字 0表示异常 1表示正常"),
            @ApiImplicitParam(name="salerauditdesc",value = "传递审核描述"),
            @ApiImplicitParam(name="salertakepoint",value = "传递销售提成")
    })
    @GetMapping("/insert")
    public BaseMessage insertSaler(Saler saler){
        BaseMessage msg = new BaseMessage();
        int rtn = salerService2.insertSaler(saler);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存成功");
        }else{
            msg.setMsg("保存失败");
        }
        return msg;
    }

    @ApiOperation("修改案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="salerid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="salerdeptid",value="传递字符串"),
            @ApiImplicitParam(name="salercode",value = "传递销售人员推荐码"),
            @ApiImplicitParam(name="salerbankname",value="传递开户银行"),
            @ApiImplicitParam(name="salerbanknum",value = "传递银行卡号"),
            @ApiImplicitParam(name="salerauditstate",value = "传递数字 0表示异常 1表示正常"),
            @ApiImplicitParam(name="salerauditdesc",value = "传递审核描述"),
            @ApiImplicitParam(name="salertakepoint",value = "传递销售提成")
    })
    @PostMapping("/update")
    public BaseMessage updateDepartment(Saler saler){
        BaseMessage msg = new BaseMessage();
        int rtn = salerService2.updateSaler(saler);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存成功");
        }else{
            msg.setMsg("保存失败");
        }
        return msg;
    }
    @ApiOperation("查询列表案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="salerid",value="传递销售人员id"),
            @ApiImplicitParam(name="salerauditstate",value = "状态，0-不可用；1-正常")
    })
    @GetMapping("/list")
    public ListMessage<SalerDto> selectSaleList(SalerDto salerDto){
            ListMessage<SalerDto> listMessage = new ListMessage<>();
            List<SalerDto> list = salerService2.selectSalerDto(salerDto);
            if(list!=null) {
                listMessage.setDatalist(list);
                listMessage.setCode(1);
            }else{
                listMessage.setCode(0);
                listMessage.setMsg("没有查询到数据");
            }
            return listMessage;
    }

    @ApiOperation("分页查询案例")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "deptname",value="传递字符串"),
//            @ApiImplicitParam(name = "deptstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/page")
    public PageMessage<SalerDto> selectSalerDtoByPage(SalerDto salerDto, Long pagenum, Long pagesize){
        Page<SalerDto> pagedata = salerService2.selectSalerDtoByPage(salerDto,pagenum,pagesize);
        PageMessage<SalerDto> msg = new PageMessage<>();
        if(pagedata!=null) {
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("分页条件查询案例")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "deptname",value="传递字符串"),
//            @ApiImplicitParam(name = "deptstate",value = "状态，0-不可用；1-正常"),
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/page2")
    public PageMessage<SalerDto> selectSalerDtoByCon(SalerDto salerDto, Long pagenum, Long pagesize){
        //System.out.println(salerDto);
        Page<SalerDto> pagedata = salerService2.selectSalerDtoByCon(salerDto,pagenum,pagesize);
        PageMessage<SalerDto> msg = new PageMessage<>();
        if(pagedata!=null) {
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("根据salerid查询一条saler信息的案例")
    @ApiImplicitParam("salerid")
    @GetMapping("/get/{salerid}")
    public PojoMessage<Saler> selectSalerById(@PathVariable("salerid") int salerid){
        PojoMessage<Saler> msg = new PojoMessage<>();
        Saler department = salerService2.selectBySalerid(salerid);
        if(department!=null){
            msg.setCode(1);
            msg.setData(department);
        }else{
            msg.setCode(0);
            msg.setMsg("没有找到指定数据");
        }
        return msg;
    }

    @ApiOperation("根据salerid查询一条salerDto信息的案例")
    @ApiImplicitParam("salerDto")
    @GetMapping("/getSalerDto/{salerid}")
    public PojoMessage<SalerDto> selectSalerDtoById(@PathVariable("salerid") int salerid){
        PojoMessage<SalerDto> msg = new PojoMessage<>();
        SalerDto salerDto = salerService2.getSalerDtoById(salerid);
        if(salerDto!=null){
            msg.setCode(1);
            msg.setData(salerDto);
        }else{
            msg.setCode(0);
            msg.setMsg("没有找到指定数据");
        }
        return msg;
    }
    @ApiOperation("修改案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="salerid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="salerdeptid",value="传递字符串"),
            @ApiImplicitParam(name="salercode",value = "传递销售人员推荐码"),
            @ApiImplicitParam(name="salerbankname",value="传递开户银行"),
            @ApiImplicitParam(name="salerbanknum",value = "传递银行卡号"),
            @ApiImplicitParam(name="usertruename",value = "真实姓名")
    })
    @GetMapping("/update2")
    public BaseMessage updateSalerDto(SalerDto  salerDto){
        BaseMessage msg = new BaseMessage();
        int rtn = salerService2.updateSalerDto(salerDto);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存成功");
        }else{
            msg.setMsg("保存失败");
        }
        return msg;
    }
    @ApiOperation("添加userSaler案例")
    @ApiImplicitParams({
            //@ApiImplicitParam(name="salerid",value = "自增长主键，不传递"),
            @ApiImplicitParam(name="username",value="用户名"),
            @ApiImplicitParam(name="issaler",value = "1表示销售人员"),
            @ApiImplicitParam(name="userpwd",value = "密码"),
            @ApiImplicitParam(name="salerauditdesc",value = "审核意见")
    })
    @PostMapping("/insert2")
    public BaseMessage insertUserSaler(User user, Saler saler){
        BaseMessage msg = new BaseMessage();
        int rtn = salerService2.inserUserSale(user,saler);
        msg.setCode(rtn);
        if(rtn>0){
            msg.setMsg("保存成功");
        }else{
            msg.setMsg("保存失败");
        }
        return msg;
    }
}
